<!--
 * @Author: delin66
 * @Date: 2025-02-28 20:38:56
 * @LastEditors: delin66
 * @LastEditTime: 2025-03-01 15:29:05
 * @Descripttion:
-->
<template>
  <div class="container">
    <div class="header">
      <div class="title">成果转化</div>
      <div class="more" @click="more">更多>></div>
    </div>
    <div class="content">
      <div class="box">
        <div class="sub_title">技术成果</div>
        <div class="notice-list">
          <ul>
            <li
              v-for="item in achievementInfo.list"
              :key="item.id"
              @click="toAchievementDetail(item.id)"
            >
              <span class="title ellipsis">
                {{ item.title }}
              </span>
              <span class="create-time">{{ item.releaseTime?.split(' ')[0] ?? '-' }}</span>
            </li>
          </ul>
          <el-empty v-if="achievementInfo.total === 0" description="没有科技成果" />
          <el-pagination
            background
            class="m-t-10 m-b-10"
            style="justify-content: flex-end"
            layout="prev, pager, next"
            :total="total"
            :page-size="10"
            v-model:current-page="current"
          />
        </div>
      </div>
      <div class="divide"></div>
      <div class="box">
        <div class="sub_title">技术需求</div>
        <div class="notice-list">
          <ul>
            <li
              v-for="item in needlist.list"
              :key="item.id"
              @click="toNeedDetail(item.id)"
            >
              <span class="title ellipsis">
                {{ item.title }}
              </span>
              <span class="create-time">{{ item.createTime?.split(' ')[0] ?? '-' }}</span>
            </li>
          </ul>
          <el-empty v-if="needlist.total === 0" description="没有技术需求" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { getAnnouncementList } from '@/api/park';
import { achievementList, needList } from '@/api/technology-transform';

import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

const total = ref(0);
const current = ref<number>(1);
// 获取公告列表
const achievementInfo = ref({
  total: 0,
  list: [] as any[],
});
const needlist = ref({
  total: 0,
  list: [] as any[],
});

function more () {
  router.push({
    name: 'achievements',
  });
}
// 跳转详情
function toAchievementDetail(id: string | number) {
  const { href } = router.resolve({
    name: 'achievementDetail',
    query: {
      aId: id,
    },
  });
  window.open(href, '_blank');
}
function toNeedDetail(nId: string | number) {
  const { href } = router.resolve({
    name: 'needDetail',
    query: {
      nId,
    },
  });
  window.open(href, '_blank');
}

function getNoticeList() {
  const query = {
    size: 10,
    current: current.value,
  };
  achievementList(query).then((res: any) => {
    achievementInfo.value.total = res.data.total;
    if (res?.code === 200) {
      achievementInfo.value.total = res.data.total;
      achievementInfo.value.list = res.data.records;
    }
  });
}
function getNeedList() {
  const query = {
    size: 10,
    current: current.value,
  };
  needList(query).then((res: any) => {
    needlist.value.total = res.data.total;
    if (res?.code === 200) {
      needlist.value.total = res.data.total;
      needlist.value.list = res.data.records;
    }
  });
}

onMounted(() => {
  getNoticeList();
  getNeedList()
});
</script>

<style scoped lang="scss">
.container {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 500px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  .header {
    display: flex;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 25px;
    font-weight: bold;
    color: white;
    background-color: #0370c2;
    clip-path: polygon(0 0, 100% 0, 100% 85%, 96% 85%, 96% 100%, 4% 100%, 4% 85%, 0 85%);
    .title {
      margin: 0 auto;
      font-weight: bolder;
    }
    .more {
      margin-right: 40px;
      font-weight: bold;
      font-size: 16px;
      cursor: pointer;
      z-index: 99;
    }
  }

  .content {
    height: 450px;
    display: flex;
    justify-content: space-between;
    .box {
      width: 50%;
      .sub_title {
        width: 60%;
        margin: 10px auto;
        text-align: center;
        line-height: 40px;
        font-size: 20px;
        font-weight: bold;
        border-bottom: 2px #338ccb solid;
      }
    }
    .divide {
      margin: auto 0;
      height: 80%;
      width: 1px;
      background-color: rgba(0, 0, 0, 0.1);
    }
  }
}
.notice-list {
  padding: 0 30px;
  flex: 1;
  width: 100%;
  padding-top: 5px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  li {
    position: relative;
    padding: 0 5%;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    &::before {
      content: '';
      position: absolute;
      width: 5px;
      height: 5px;
      background-color: #338ccb;
      top: 50%;
      left: 2.5%;
      transform: translate(-50%, -50%);
    }
    .title {
        margin-left: 10px;
      max-width: 85%;
      font-size: 16px;
      &:hover {
        cursor: pointer;
        color: #338ccb;
      }
    }
    .create-time {
        text-wrap: nowrap;
    }
  }
}
</style>
